package com.shou.zhnfyxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shou.zhnfyxt.entity.HouseDetail;
import com.shou.zhnfyxt.entity.HouseRecommendation;
import com.shou.zhnfyxt.entity.R;
import com.shou.zhnfyxt.mapper.HouseRecommendationDao;
import com.shou.zhnfyxt.service.HouseDetailService;
import com.shou.zhnfyxt.service.IHouseRecommendationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JCY
 * @since 2022-12-30
 */
@Service
public class HouseRecommendationServiceImpl extends ServiceImpl<HouseRecommendationDao, HouseRecommendation> implements IHouseRecommendationService {
@Autowired
private IHouseRecommendationService houseRecommendationService;

@Autowired
private HouseDetailService houseDetailService;
    @Override
    public R<List<HouseDetail>> getHotClick() {
        QueryWrapper<HouseRecommendation> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("house_click");
        queryWrapper.last("limit 3");
        List<HouseRecommendation> list = houseRecommendationService.list(queryWrapper);
        Collection<Integer> collect = list.stream().map(HouseRecommendation::getHouseId).collect(Collectors.toList());
        List<HouseDetail> houseDetailList = houseDetailService.listByIds(collect);
        return R.success(houseDetailList);
    }
}
